
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/28/2014 20:40:28
-- Generated from EDMX file: F:\Work\EquationsBank\equations-bank\EquationsBankReader\DatabaseStructure\DBEntities.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [EquationsDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Equation_NameEquation_Name_Language]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Name_Language] DROP CONSTRAINT [FK_Equation_NameEquation_Name_Language];
GO
IF OBJECT_ID(N'[dbo].[FK_Equation_FormulaEquation_Formula_Variable]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Formula_Variable] DROP CONSTRAINT [FK_Equation_FormulaEquation_Formula_Variable];
GO
IF OBJECT_ID(N'[dbo].[FK_EquationEquation_Formula]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Formula] DROP CONSTRAINT [FK_EquationEquation_Formula];
GO
IF OBJECT_ID(N'[dbo].[FK_EquationEquation_Reference]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Reference] DROP CONSTRAINT [FK_EquationEquation_Reference];
GO
IF OBJECT_ID(N'[dbo].[FK_EquationEquation_Citation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Citation] DROP CONSTRAINT [FK_EquationEquation_Citation];
GO
IF OBJECT_ID(N'[dbo].[FK_EquationEquation_Description]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Description] DROP CONSTRAINT [FK_EquationEquation_Description];
GO
IF OBJECT_ID(N'[dbo].[FK_Equation_DescriptionEquation_Description_Language]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Description_Language] DROP CONSTRAINT [FK_Equation_DescriptionEquation_Description_Language];
GO
IF OBJECT_ID(N'[dbo].[FK_Equation_PathEquation_Path_Language]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Path_Language] DROP CONSTRAINT [FK_Equation_PathEquation_Path_Language];
GO
IF OBJECT_ID(N'[dbo].[FK_EquationSettings]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equations] DROP CONSTRAINT [FK_EquationSettings];
GO
IF OBJECT_ID(N'[dbo].[FK_SettingsEnableSolver]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Settings] DROP CONSTRAINT [FK_SettingsEnableSolver];
GO
IF OBJECT_ID(N'[dbo].[FK_EquationEquation_Name]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Name] DROP CONSTRAINT [FK_EquationEquation_Name];
GO
IF OBJECT_ID(N'[dbo].[FK_EquationEquation_Path]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Equation_Path] DROP CONSTRAINT [FK_EquationEquation_Path];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Equations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equations];
GO
IF OBJECT_ID(N'[dbo].[Equation_Path]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Path];
GO
IF OBJECT_ID(N'[dbo].[Equation_Name]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Name];
GO
IF OBJECT_ID(N'[dbo].[Equation_Name_Language]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Name_Language];
GO
IF OBJECT_ID(N'[dbo].[Equation_Formula]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Formula];
GO
IF OBJECT_ID(N'[dbo].[Equation_Formula_Variable]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Formula_Variable];
GO
IF OBJECT_ID(N'[dbo].[Equation_Reference]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Reference];
GO
IF OBJECT_ID(N'[dbo].[Equation_Citation]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Citation];
GO
IF OBJECT_ID(N'[dbo].[Equation_Description]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Description];
GO
IF OBJECT_ID(N'[dbo].[Equation_Description_Language]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Description_Language];
GO
IF OBJECT_ID(N'[dbo].[Equation_Path_Language]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Equation_Path_Language];
GO
IF OBJECT_ID(N'[dbo].[Settings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Settings];
GO
IF OBJECT_ID(N'[dbo].[EnableSolvers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EnableSolvers];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Equation_Path'
CREATE TABLE [dbo].[Equation_Path] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Equation_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Name'
CREATE TABLE [dbo].[Equation_Name] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Equation_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Name_Language'
CREATE TABLE [dbo].[Equation_Name_Language] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Equation_Name_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Formula'
CREATE TABLE [dbo].[Equation_Formula] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Representation] nvarchar(max)  NOT NULL,
    [Image] nvarchar(max)  NULL,
    [Equation_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Formula_Variable'
CREATE TABLE [dbo].[Equation_Formula_Variable] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [TypeName] nvarchar(max)  NOT NULL,
    [TypeValue] nvarchar(max)  NOT NULL,
    [Equation_Formula_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Reference'
CREATE TABLE [dbo].[Equation_Reference] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [ReferenceName] nvarchar(max)  NOT NULL,
    [ReferenceValue] nvarchar(max)  NOT NULL,
    [Equation_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Citation'
CREATE TABLE [dbo].[Equation_Citation] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [CitationName] nvarchar(max)  NOT NULL,
    [CitationValue] nvarchar(max)  NOT NULL,
    [Equation_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Description'
CREATE TABLE [dbo].[Equation_Description] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Equation_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Description_Language'
CREATE TABLE [dbo].[Equation_Description_Language] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Equation_Description_ID] int  NOT NULL
);
GO

-- Creating table 'Equation_Path_Language'
CREATE TABLE [dbo].[Equation_Path_Language] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Equation_Path_ID] int  NOT NULL
);
GO

-- Creating table 'EnableSolvers'
CREATE TABLE [dbo].[EnableSolvers] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Setting_ID] int  NOT NULL
);
GO

-- Creating table 'Equations'
CREATE TABLE [dbo].[Equations] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Settings'
CREATE TABLE [dbo].[Settings] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Equation_ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Equation_Path'
ALTER TABLE [dbo].[Equation_Path]
ADD CONSTRAINT [PK_Equation_Path]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Name'
ALTER TABLE [dbo].[Equation_Name]
ADD CONSTRAINT [PK_Equation_Name]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Name_Language'
ALTER TABLE [dbo].[Equation_Name_Language]
ADD CONSTRAINT [PK_Equation_Name_Language]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Formula'
ALTER TABLE [dbo].[Equation_Formula]
ADD CONSTRAINT [PK_Equation_Formula]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Formula_Variable'
ALTER TABLE [dbo].[Equation_Formula_Variable]
ADD CONSTRAINT [PK_Equation_Formula_Variable]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Reference'
ALTER TABLE [dbo].[Equation_Reference]
ADD CONSTRAINT [PK_Equation_Reference]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Citation'
ALTER TABLE [dbo].[Equation_Citation]
ADD CONSTRAINT [PK_Equation_Citation]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Description'
ALTER TABLE [dbo].[Equation_Description]
ADD CONSTRAINT [PK_Equation_Description]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Description_Language'
ALTER TABLE [dbo].[Equation_Description_Language]
ADD CONSTRAINT [PK_Equation_Description_Language]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equation_Path_Language'
ALTER TABLE [dbo].[Equation_Path_Language]
ADD CONSTRAINT [PK_Equation_Path_Language]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'EnableSolvers'
ALTER TABLE [dbo].[EnableSolvers]
ADD CONSTRAINT [PK_EnableSolvers]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Equations'
ALTER TABLE [dbo].[Equations]
ADD CONSTRAINT [PK_Equations]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Settings'
ALTER TABLE [dbo].[Settings]
ADD CONSTRAINT [PK_Settings]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Equation_Name_ID] in table 'Equation_Name_Language'
ALTER TABLE [dbo].[Equation_Name_Language]
ADD CONSTRAINT [FK_Equation_NameEquation_Name_Language]
    FOREIGN KEY ([Equation_Name_ID])
    REFERENCES [dbo].[Equation_Name]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Equation_NameEquation_Name_Language'
CREATE INDEX [IX_FK_Equation_NameEquation_Name_Language]
ON [dbo].[Equation_Name_Language]
    ([Equation_Name_ID]);
GO

-- Creating foreign key on [Equation_Formula_ID] in table 'Equation_Formula_Variable'
ALTER TABLE [dbo].[Equation_Formula_Variable]
ADD CONSTRAINT [FK_Equation_FormulaEquation_Formula_Variable]
    FOREIGN KEY ([Equation_Formula_ID])
    REFERENCES [dbo].[Equation_Formula]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Equation_FormulaEquation_Formula_Variable'
CREATE INDEX [IX_FK_Equation_FormulaEquation_Formula_Variable]
ON [dbo].[Equation_Formula_Variable]
    ([Equation_Formula_ID]);
GO

-- Creating foreign key on [Equation_ID] in table 'Equation_Formula'
ALTER TABLE [dbo].[Equation_Formula]
ADD CONSTRAINT [FK_EquationEquation_Formula]
    FOREIGN KEY ([Equation_ID])
    REFERENCES [dbo].[Equations]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquationEquation_Formula'
CREATE INDEX [IX_FK_EquationEquation_Formula]
ON [dbo].[Equation_Formula]
    ([Equation_ID]);
GO

-- Creating foreign key on [Equation_ID] in table 'Equation_Reference'
ALTER TABLE [dbo].[Equation_Reference]
ADD CONSTRAINT [FK_EquationEquation_Reference]
    FOREIGN KEY ([Equation_ID])
    REFERENCES [dbo].[Equations]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquationEquation_Reference'
CREATE INDEX [IX_FK_EquationEquation_Reference]
ON [dbo].[Equation_Reference]
    ([Equation_ID]);
GO

-- Creating foreign key on [Equation_ID] in table 'Equation_Citation'
ALTER TABLE [dbo].[Equation_Citation]
ADD CONSTRAINT [FK_EquationEquation_Citation]
    FOREIGN KEY ([Equation_ID])
    REFERENCES [dbo].[Equations]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquationEquation_Citation'
CREATE INDEX [IX_FK_EquationEquation_Citation]
ON [dbo].[Equation_Citation]
    ([Equation_ID]);
GO

-- Creating foreign key on [Equation_ID] in table 'Equation_Description'
ALTER TABLE [dbo].[Equation_Description]
ADD CONSTRAINT [FK_EquationEquation_Description]
    FOREIGN KEY ([Equation_ID])
    REFERENCES [dbo].[Equations]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquationEquation_Description'
CREATE INDEX [IX_FK_EquationEquation_Description]
ON [dbo].[Equation_Description]
    ([Equation_ID]);
GO

-- Creating foreign key on [Equation_Description_ID] in table 'Equation_Description_Language'
ALTER TABLE [dbo].[Equation_Description_Language]
ADD CONSTRAINT [FK_Equation_DescriptionEquation_Description_Language]
    FOREIGN KEY ([Equation_Description_ID])
    REFERENCES [dbo].[Equation_Description]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Equation_DescriptionEquation_Description_Language'
CREATE INDEX [IX_FK_Equation_DescriptionEquation_Description_Language]
ON [dbo].[Equation_Description_Language]
    ([Equation_Description_ID]);
GO

-- Creating foreign key on [Equation_Path_ID] in table 'Equation_Path_Language'
ALTER TABLE [dbo].[Equation_Path_Language]
ADD CONSTRAINT [FK_Equation_PathEquation_Path_Language]
    FOREIGN KEY ([Equation_Path_ID])
    REFERENCES [dbo].[Equation_Path]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Equation_PathEquation_Path_Language'
CREATE INDEX [IX_FK_Equation_PathEquation_Path_Language]
ON [dbo].[Equation_Path_Language]
    ([Equation_Path_ID]);
GO

-- Creating foreign key on [Equation_ID] in table 'Equation_Path'
ALTER TABLE [dbo].[Equation_Path]
ADD CONSTRAINT [FK_EquationEquation_Path]
    FOREIGN KEY ([Equation_ID])
    REFERENCES [dbo].[Equations]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquationEquation_Path'
CREATE INDEX [IX_FK_EquationEquation_Path]
ON [dbo].[Equation_Path]
    ([Equation_ID]);
GO

-- Creating foreign key on [Equation_ID] in table 'Equation_Name'
ALTER TABLE [dbo].[Equation_Name]
ADD CONSTRAINT [FK_EquationEquation_Name]
    FOREIGN KEY ([Equation_ID])
    REFERENCES [dbo].[Equations]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquationEquation_Name'
CREATE INDEX [IX_FK_EquationEquation_Name]
ON [dbo].[Equation_Name]
    ([Equation_ID]);
GO

-- Creating foreign key on [Equation_ID] in table 'Settings'
ALTER TABLE [dbo].[Settings]
ADD CONSTRAINT [FK_EquationSettings]
    FOREIGN KEY ([Equation_ID])
    REFERENCES [dbo].[Equations]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquationSettings'
CREATE INDEX [IX_FK_EquationSettings]
ON [dbo].[Settings]
    ([Equation_ID]);
GO

-- Creating foreign key on [Setting_ID] in table 'EnableSolvers'
ALTER TABLE [dbo].[EnableSolvers]
ADD CONSTRAINT [FK_SettingsEnableSolver]
    FOREIGN KEY ([Setting_ID])
    REFERENCES [dbo].[Settings]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SettingsEnableSolver'
CREATE INDEX [IX_FK_SettingsEnableSolver]
ON [dbo].[EnableSolvers]
    ([Setting_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------